home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Method / MethodOf.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  846 b   |  45 lines  |  [TEXT/CWIE]

  1. // MethodOf.h
  2.  
  3. #ifndef MethodOf_h
  4. #define MethodOf_h
  5.  
  6. #ifndef Method_h
  7. #include "Method.h"
  8. #endif
  9. #ifndef Integers_h
  10. #include "Integers.h"
  11. #endif
  12.  
  13. template < class TheTargetType >
  14. class MethodOf: public Method
  15.   {
  16.     typedef TheTargetType TargetType;
  17.     typedef void (TargetType::*MemberType)();
  18.     
  19.     private:
  20.         TargetType *target;
  21.         MemberType method;
  22.     
  23.     public:
  24.         MethodOf( TargetType *theTarget, MemberType theMethod )
  25.           : target( theTarget ),
  26.              method( theMethod )
  27.           {}
  28.         
  29.         TargetType *Target() const            { return target; }
  30.         MemberType Method() const            { return method; }
  31.         
  32.         void SetTarget( TargetType *t )    { target = t; }
  33.         void SetMethod( MemberType m )    { method = m; }
  34.         
  35.         bool Null() const        { return target == 0 || method == 0; }
  36.         
  37.         virtual void operator()() const
  38.           {
  39.             if ( !Null() )
  40.                 (target->*method)();
  41.           }
  42.   };
  43.  
  44. #endif
  45.